<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${book.id != null} ? '编辑书籍' : '新增书籍'">书籍表单</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <h1 class="mt-4" th:text="${book.id != null} ? '编辑书籍' : '新增书籍'"></h1>

    <form th:action="${book.id != null} ? @{/book/update} : @{/book}" method="post">
        <!-- 如果是编辑模式，添加隐藏的ID字段 -->
        <input type="hidden" th:if="${book.id != null}" name="id" th:value="${book.id}"/>

        <div class="form-group">
            <label for="name">书名</label>
            <input type="text" class="form-control" id="name" name="name" th:value="${book.name}" required/>
        </div>

        <div class="form-group">
            <label for="type">类型</label>
            <input type="text" class="form-control" id="type" name="type" th:value="${book.type}" required/>
        </div>

        <div class="form-group">
            <label for="author">作者</label>
            <input type="text" class="form-control" id="author" name="author" th:value="${book.author}" required/>
        </div>

        <div class="form-group">
            <label for="price">价格</label>
            <input type="number" class="form-control" id="price" name="price" th:value="${book.price}" step="0.01"
                   required/>
        </div>

        <!-- 根据模式显示不同的按钮 -->
        <button type="submit" class="btn btn-primary" th:text="${book.id != null} ? '更新' : '保存'"></button>
        <a href="/books" class="btn btn-secondary">取消</a>
    </form>
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
